﻿@model List<Model.ViewModel.ProductViewModel>
@{
    ViewBag.Title = "Kết quả tìm kiếm";
    Layout = "~/Views/Shared/_Layout.cshtml";

}
<div class="content">
    <div class="content_top">
        <div class="heading">
            <h3>Kết quả tìm kiếm theo từ khoá: @ViewBag.Keyword</h3>
        </div>
        <div class="see">
            <p><a href="#">See all Products</a></p>
        </div>
        <div class="clear"></div>
    </div>
    <div class="section group">
        @if (Model.Count > 0)
        {
            foreach (var item in Model)
            {
                var link = "/chi-tiet/" + item.MetaTitle + "-" + item.ID;
                <div class="grid_1_of_4 images_1_of_4">
                    <a href="@link"><img src="@item.Images" alt="" /></a>
                    <h2>@item.Name</h2>
                    <span>@item.CateName</span>
                    <div class="price-details">
                        <div class="price-number">
                            <p><span class="rupees">@(item.Price.HasValue ? item.Price.Value.ToString("N0") : "Liên hệ")</span></p>
                        </div>
                        <div class="add-cart">
                            <h4><a href="/gio-hang/@item.ID">Thêm vào giỏ</a></h4>
                        </div>
                        <div class="clear"></div>
                    </div>

                </div>
            }
            <div class="clear"></div>
        <!--Phân trang-->
            if (ViewBag.TotalPage > 1)
            {
                var pageDisplay = (int)ViewBag.MaxPage;
                int totalPage = (int)ViewBag.TotalPage;
                int currentPage = ((int)ViewBag.Page);

                // Create numeric links
                var startPageIndex = Math.Max(1, currentPage - pageDisplay / 2);
                var endPageIndex = Math.Min(totalPage, currentPage + pageDisplay / 2);

                var link = "/tim-kiem?keyword=" + ViewBag.Keyword;
                <nav>
                    <ul class="pagination">
                        @if (currentPage > ViewBag.First)
                        {
                            <li><a href="@link&page=@ViewBag.First" title="Trang đầu" class="first"><i class="fa fa-angle-double-left"></i></a></li>
                            <li>
                                <a href="@link&page=@ViewBag.Prev" title="Trang trước" class="prev"><i class="fa fa-angle-left"></i></a>
                            </li>

                        }
                        @for (int i = startPageIndex; i <= endPageIndex; i++)
                    {
                        if (currentPage == i)
                        {

                                <li> <a href="@link&page=@i" class="active" title="Trang @i">@i</a></li>
                            }
                            else
                            {
                                <li><a href="@link&page=@i" title="Trang @i" class="pos">@i</a></li>
                            }
                        }
                        @if (currentPage < totalPage)
                    {
                            <li><a href="@link&page=@ViewBag.Next" class="next" title="Trang sau"><i class="fa fa-angle-right"></i></a></li>
                            <li> <a href="@link&page=@ViewBag.Last" class="last" title="Trang cuối"><i class="fa fa-angle-double-right"></i></a></li>
                        }

                    </ul>
                </nav>

            }
        }
        else
        {
            <span>Không có bản ghi nào</span>
        }


    </div>
</div>
